import React from 'react';
import { Component, useEffect, useState } from 'react';
import { Button, Pagination, Table, Form, Select, Input } from 'antd';
import request from '../../../http';
import { history } from 'umi';
import './PersonScore.css';

const { Option } = Select;
const { TextArea } = Input;

const columns = [
  {
    title: '作业主题',
    dataIndex: '作业主题',
    key: '1',
  },
  {
    title: '下发老师',
    dataIndex: '下发老师',
    key: '2',
  },
  {
    title: '下发时间',
    dataIndex: '下发时间',
    key: '3',
  },
  {
    title: '提交时间',
    dataIndex: '提交时间',
    key: '4',
  },
  {
    title: '实际提交时间',
    dataIndex: '实际提交时间',
    key: '5',
  },
  {
    title: '提交情况',
    dataIndex: '提交情况',
    key: '6',
  },
  {
    title: '作业得分',
    dataIndex: '作业得分',
    key: '7',
  },
  {
    title: '操作',
    dataIndex: '操作',
    key: '8',
    render: (record) => {
      return <a onClick={() => ChaKanXiangQing()}>查看详情</a>;
    },
  },
];

//查看详情
const ChaKanXiangQing = () => {
  alert('还为完成该功能！');
  history.push({
    pathname: '/admin/Comprehensive/GroupComprehensive',
    // query: {
    //   courseId: courseId,
    //   studentId: studentId
    // }
  });
};

const Info = () => {
  //保存接收过来的数据
  const [imformation, setimformation] = useState([{}]);
  //个人综合打分-查询学生历史作业信息-表格数据
  const [data, setdata] = useState([{}]);
  //接收的分页数
  const [sum, setsum] = useState(1);
  const [sumPage, setsumPage] = useState(1);

  //获取传过来的数据
  const courseId = history.location.query.courseId;
  const projectGrupId = history.location.query.projectGrupId;

  //周期函数
  useEffect(() => {
    // 请求小组详情接口
    request
      .post('/scoring/a_t/queryGroupScoreConditionDetails', {
        courseId,
        projectGrupId,
      })
      .then((res) => {
        console.log('小组详情请求成功', res);
        setimformation(res.data);
      })
      .catch((err) => console.log('个人详情失败', err));

    //小组综合打分-查询小组历史作业信息
    request
      .post('/scoring/a_t/queryGroupWork', {
        number: 10,
        page: 1,
        courseId, //imformation.courseId
        projectGrupId, //imformation.studentId
      })
      .then((res) => {
        // console.log("小组综合打分-查询小组历史作业信息请求成功", res)
        if (res.success == false) {
          setdata('');
        } else {
          const p = res.data.returnDate;
          const newP = p.map((pObj) => {
            return {
              作业主题: pObj.workTheme,
              下发老师: pObj.teacherName,
              下发时间: pObj.releaseDateTime,
              提交时间: pObj.completionDateTime,
              实际提交时间: pObj.submitTime,
              提交情况: pObj.type,
              作业得分: pObj.score,
              workdId: pObj.workId,
            };
          });
          setdata(newP);
          setsum(res.data.paginationData.sum);
          setsumPage(res.data.paginationData.sumPage);
        }
      });
  }, []);

  //分页
  const onChange = (page, pageSize) => {
    //请求
    request
      .post('/scoring/a_t/queryGroupWork', {
        number: pageSize,
        page: page,
        courseId, //imformation.courseId
        projectGrupId, //imformation.studentId
      })
      .then((res) => {
        // console.log("小组综合打分-查询小组历史作业信息请求成功", res)
        if (res.success == false) {
          setdata('');
        } else {
          const p = res.data.returnDate;
          const newP = p.map((pObj) => {
            return {
              作业主题: pObj.workTheme,
              下发老师: pObj.teacherName,
              下发时间: pObj.releaseDateTime,
              提交时间: pObj.completionDateTime,
              实际提交时间: pObj.submitTime,
              提交情况: pObj.type,
              作业得分: pObj.score,
              workdId: pObj.workId,
            };
          });
          setdata(newP);
          setsum(res.data.paginationData.sum);
          setsumPage(res.data.paginationData.sumPage);
        }
      });
  };

  //返回跳转
  const Back = () => {
    history.push('/admin/mark/group/group');
  };

  return (
    <div>
      <h2>小组综合评分</h2>
      <Form>
        <div style={{ marginTop: -170 }}>
          <div className="prjName">
            小组:
            <Input
              style={{
                position: 'absolute',
                bottom: -5,
                width: 200,
                marginLeft: 12,
              }}
              value={imformation.projectGrupId}
              disabled={true}
            />
          </div>
          <div className="groupName" style={{ marginLeft: 320 }}>
            小组长:
            <Input
              style={{
                position: 'absolute',
                bottom: -5,
                width: 200,
                marginLeft: 12,
              }}
              value={imformation.groupLeaderName}
              disabled={true}
            />
          </div>
          <div className="groupName" style={{ marginLeft: 600 }}>
            成员数:
            <Input
              style={{
                position: 'absolute',
                bottom: -5,
                width: 200,
                marginLeft: 12,
              }}
              value={imformation.total}
              disabled={true}
            />
          </div>
          <div className="groupName" style={{ marginLeft: 920 }}>
            成员:
            <Input
              style={{
                position: 'absolute',
                bottom: -5,
                width: 200,
                marginLeft: 12,
              }}
              value={imformation.studentNames}
              disabled={true}
            />
          </div>

          <div className="prjName" style={{ marginTop: 100 }}>
            院系:
            <Input
              style={{
                position: 'absolute',
                bottom: -5,
                width: 200,
                marginLeft: 12,
              }}
              value={imformation.dkey}
              disabled={true}
            />
          </div>
          <div
            className="groupName"
            style={{ marginLeft: 320, marginTop: 100 }}
          >
            项目名称:
            <Input
              style={{
                position: 'absolute',
                bottom: -5,
                width: 200,
                marginLeft: 12,
              }}
              value={imformation.courseName}
              disabled={true}
            />
          </div>
          <div
            className="groupName"
            style={{ marginLeft: 600, marginTop: 100 }}
          >
            实训老师:
            <Input
              style={{
                position: 'absolute',
                bottom: -5,
                width: 200,
                marginLeft: 12,
              }}
              value={imformation.trainingTeacherNames}
              disabled={true}
            />
          </div>
          <div
            className="groupName"
            style={{ marginLeft: 920, marginTop: 100 }}
          >
            责任老师:
            <Input
              style={{
                position: 'absolute',
                bottom: -5,
                width: 200,
                marginLeft: 12,
              }}
              value={imformation.responsibilityName}
              disabled={true}
            />
          </div>

          <div className="prjName" style={{ marginTop: 170 }}>
            综合打分:
            <Input
              style={{
                position: 'absolute',
                bottom: -5,
                width: 200,
                marginLeft: 12,
              }}
              value={imformation.score}
              disabled={true}
            />
          </div>
          <div
            className="groupName"
            style={{ marginLeft: 320, marginTop: 170 }}
          >
            评语:{' '}
            <TextArea
              rows={4}
              style={{ marginLeft: 65, marginTop: -28 }}
              value={imformation.comment}
              disabled={true}
            />
          </div>

          <div>
            {imformation.state == 1 ? (
              <Button
                type="primary"
                style={{
                  position: 'absolute',
                  left: 1550,
                  top: 200,
                  padding: '5px 20px',
                }}
              >
                保存
              </Button>
            ) : undefined}
            <Button
              style={{
                position: 'absolute',
                left: 1650,
                top: 200,
                padding: '5px 20px',
              }}
              onClick={Back}
            >
              返回
            </Button>
          </div>
        </div>

        <div className="form" style={{ marginTop: 200 }}>
          <Table
            columns={columns}
            dataSource={data}
            pagination={false}
            style={{ position: 'relative', top: 250, width: 1320 }}
          />
          <div>
            <Pagination
              total={sum}
              onChange={onChange}
              hideOnSinglePage={true}
              style={{ position: 'relative', top: 250 }}
            />
          </div>
        </div>
      </Form>
    </div>
  );
};

export default Info;
